package com.kefu.chat.smart.action;

import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.springframework.beans.factory.annotation.Autowired;

import com.kefu.chat.model.ChatUser;
import com.kefu.chat.service.ChatAdminService;
import com.kefu.chat.service.ChatCacheService;
import com.kefu.chat.service.ChatSessionService;
import com.kefu.chat.smart.ChatConnectAction;
import com.kefu.chat.vo.ChatUserParam.UserConnectP;
import com.kefu.chat.vo.ChatUserParam.UserConnectR;
import com.kefu.common.trigger.Action;
import com.kefu.common.trigger.TriggerWrapper;
import com.kefu.common.trigger.model.ActionModel;
import com.kefu.smart.special.QueueStrategy;

//@Component
public class ChatConnectLastAdminAction implements ChatConnectAction{

	@Autowired
    private ChatCacheService chatCacheService;
    @Autowired
    private ChatAdminService chatAdminService;
    @Autowired
    private ChatSessionService chatSessionService;
    
	    
	@Override
	public boolean doAction(TriggerWrapper<UserConnectP, UserConnectR> wrapper, Action action) {
		
		UserConnectP param=new UserConnectP();
		ChatUser user=getChatUser(wrapper);
		param.setUserId(wrapper.getNewObj().getUserId());
		param.setGroupId(wrapper.getNewObj().getGroupId());
		param.setAdminId(user.getLastAdminId());
		
		boolean queue=QueueStrategy.Queue.name().equals(action.getSubAction());
		param.setQueue(queue);
		wrapper.getActionObj().getActions().add(param);
		return false;
		
	}
	

	@Override
	public ActionModel getActionModel() {
		return ActionModel.builder()
				.code(getCode())
				.name(getMessageName())
				.children(Stream.of(QueueStrategy.values())
								.map(strategy->strategy.getActionModel())
								.collect(Collectors.toList()))
				.build();
	}

	@Override
	public String getCode() {
		return "last_admin";
	}

	@Override
	public String getName() {
		return "分配到上次接待人";
	}


}
